package com.kingdee.pda.ui.one_click_return;

import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.ImageView;
import android.widget.TextView;

import com.example.basecommon.http.rxjava.BaseResponse;
import com.kingdee.pda.R;
import com.kingdee.pda.entity.Warehouse;
import com.kingdee.pda.ui.activity.BaseTitleActivity;

import butterknife.BindView;
import butterknife.OnClick;

/**
 * 一键退货结果展示
 * * Created by dlj
 * DATE 2021/11/30
 * TIME 15:20
 */
public class OneClickReturnResultActivity extends BaseTitleActivity {
    public static final int REQUEST_CODE = 2000;

    @BindView(R.id.iv_icon)
    ImageView iv_icon;
    @BindView(R.id.tv_success)
    TextView tv_success;
    @BindView(R.id.tv_content)
    TextView tv_content;
    private BaseResponse<ScanSnResultBean> response;

    public static void actionStartForResult(Activity context, BaseResponse<ScanSnResultBean> snCode) {
        Intent intent = new Intent(context, OneClickReturnResultActivity.class);
        intent.putExtra("result", snCode);
        context.startActivityForResult(intent, REQUEST_CODE);
    }

    @Override
    public void changeWarehouse(Warehouse warehouse) {

    }

    @Override
    protected void onActivityCreate(Bundle savedInstanceState) {
        super.onActivityCreate(savedInstanceState);
        setContentView(R.layout.activity_one_click_return_result);
    }

    @Override
    protected void initView() {
        super.initView();
        setTitle("一键退货");
    }

    @Override
    protected void initData() {
        super.initData();

        try {
            response = (BaseResponse<ScanSnResultBean>) getIntent().getSerializableExtra("result");
            if (response.success == true) {
                iv_icon.setBackground(getResources().getDrawable(R.mipmap.icon_operate_success));
                tv_success.setText("退货成功");
                tv_content.setText(getResultContent(response.data));
            } else {
                iv_icon.setBackground(getResources().getDrawable(R.mipmap.icon_operate_failed));
                tv_success.setText("退货失败");
                tv_content.setText(response.message);
            }
        } catch (Exception e) {
            e.printStackTrace();
        }
    }

    private String getResultContent(ScanSnResultBean data) {
        StringBuffer sb = new StringBuffer();
        sb.append("货主：" + data.getOwner());
        sb.append("\n");
        sb.append("入库单号：" + data.getBillno());
        sb.append("\n");
        sb.append("商品编码：" + data.getItem());
        sb.append("\n");
        sb.append("商品序列号：" + data.getSn());
        sb.append("\n");
        sb.append("规格名称：" + data.getItemskuname());
        sb.append("\n");
        sb.append("收货仓库：" + data.getWarehouse());
        return sb.toString();
    }

    @OnClick({R.id.btn_return, R.id.btn_fiinish})
    public void onViewClicked(View view) {
        Intent intent = getIntent();
        Bundle bundle = new Bundle();
        switch (view.getId()) {
            case R.id.btn_return:
                bundle.putString("result", "1");
                intent.putExtras(bundle);
                setResult(RESULT_OK, intent);
                finish();
                break;
            case R.id.btn_fiinish:
                bundle.putString("result", "2");
                intent.putExtras(bundle);
                setResult(RESULT_OK, intent);
                finish();
                break;
            default:
                break;
        }
    }
}
